package
{
	import com.yzy.loader.DataLoader;
	import com.yzy.tool.ReadFile;
	
	import flash.display.Sprite;
	import flash.net.URLLoaderDataFormat;
	
	
	public class NumberAnalysis extends Sprite
	{
		private var numVer:Vector.<NumObj>;
		public function NumberAnalysis()
		{
			//trace(ReadFile.ExtractProperty("aaaaa/bbb/20130225.txt","name"));
			ReadFile.ExtractProperty("cqss.txt");
			DataLoader.loaderData("cqss.txt",loaderComplete,loaderProgress,URLLoaderDataFormat.TEXT);
		}
		private function loaderProgress(bytesTotal:Number,bytesLoaded:Number):void{
			
		}
		protected  function loaderComplete(data:String):void
		{
			//trace(data)
			numVer=ReadFile.strToVector(data,NumObj,Vector.<NumObj>) as Vector.<NumObj>;
		
			ff5();
		}
		
		//上一期末尾号 会出现在下一期的数据
		private function ff1():void{
			var zcs:int=numVer.length;
			var fhNum:int=0;
			//
			var PreviousArr1:Array=numVer.shift().number.split(" ");
			var PreviouslastNum:String=PreviousArr1[PreviousArr1.length-1];
			//符合要求的
			for (var i:int = 0; i < numVer.length; i++) 
			{
				var currNumarr:Array=numVer[i].number.split(" ");
				var currArrLastNum:String=currNumarr[currNumarr.length-1];
				//末尾号码会出现在下一期	
				if(currNumarr.indexOf(PreviouslastNum)>=0){
					fhNum++;
				}else{
					
				}
				PreviouslastNum=currArrLastNum;
			}
			
			trace("总共期数="+zcs);
			trace("符合条件的期数="+fhNum);
			trace("比值="+fhNum/zcs);
		}
		
		// 连续3次以上出现的情况
		private function ff2():void{
			var zcs:int=numVer.length;
			var fhNum:int=0;
			//
			var PreviousArr1:Array=numVer.shift().number.split(",");
			var PreviouslastNum:String=PreviousArr1[PreviousArr1.length-1];
			//符合要求的
			var tempNum:int=0
			for (var i:int = 0; i < numVer.length; i++) 
			{
				var currNumarr:Array=numVer[i].number.split(",");
				var currArrLastNum:String=currNumarr[currNumarr.length-1];
				//末尾号码会出现在下一期	
				if(currNumarr.indexOf(PreviouslastNum)>=0){
					tempNum++;
					if(tempNum>=3){
						fhNum++;
						trace(tempNum)
						//trace(numVer[i].date)
					}
				}else{
					tempNum=0;
				}
				PreviouslastNum=currArrLastNum;
			}
			trace("总共期数="+zcs);
			trace("符合条件的期数="+fhNum);
			trace("比值="+fhNum/zcs);
		}
		
		// 6次 为一个周期 计算 0~9 出现过没有; 出现过为1 没有为-1  计算 +1 -1 的比值
		private function ff3():void{
			var zcs:int=numVer.length;//总共的期数
			var zhen:int=0;//+1的 计数值
			var fu:int=0;//-1的 计数值
			const limt:int=6;//每6期 一个周期
			const testNum:String="9";
			for (var i:int = 0; i < zcs; i++) 
			{
				for (var j:int = 0; j < limt; j++) 
				{
					var isHas:Boolean=false;
					var tempNum:int=i+j;
					if(tempNum<zcs){
						var currNumarr:Array=numVer[tempNum].number.split(",");//每一期的数分成数组
						if(currNumarr.indexOf(testNum)>=0){//测试 数 是否在 这一期的数组里
							isHas=true;
							break;
						}
					}
				}
				if(isHas){
					zhen++;
				}else{
					fu++;
				}
			}
			trace("总共期数="+zcs);
			trace("测试的数="+testNum);
			trace("6期之内出现的情况="+zhen);
			trace("6期之内没出现的情况="+fu);
			trace("正负比值="+zhen/fu);
		}
		
		//每一个数 出现的 次数
		private function ff4():void{
			const testNum:String="9";
			var zcs:int=numVer.length;
			var zhen:int=0;
			
			for (var i:int = 0; i < zcs; i++) 
			{
				var currNumarr:Array=numVer[i].number.split(",");
				if(currNumarr.indexOf(testNum)>=0){
					zhen++;
				}
			}
			
			
			trace("总共期数="+zcs);
			trace("测试的数="+testNum);
			trace("出现的期数="+zhen);
			trace("正负比="+zhen/(zcs-zhen));
		}

		private function ff5():void{
			var zcs:int=numVer.length;//总共的期数
			var num10:int=0;
			var num9:int=0;
			var num8:int=0;
			var num7:int=0;
			var num6:int=0;
			var num5:int=0;
			var num4:int=0;
			var num3:int=0;
			var num2:int=0;
			var num1:int=0;
			const limt:int=6;//每6期 一个周期
			
			for (var i:int = 0; i < zcs; i++) 
			{
				var temparr:String=new String();
				for (var j:int = 0; j < limt; j++) 
				{
					var tempNum:int=i+j;
					if(tempNum<zcs){
						if(j!=limt-1){
							temparr+=numVer[tempNum].number+",";//每一期的数分成数组
						}else{
							temparr+=numVer[tempNum].number
						}
					}
				}
				
				var numArr:Array=temparr.split(",");
				var temp2arr:Array=new Array();
				for (var k:int = 0; k < 10; k++) 
				{
					if(numArr.indexOf(String(k))>=0){
						temp2arr.push(k);
					}
				}
				
				//trace(temparr);
				//trace(temp2arr);
				
				switch(temp2arr.length)
				{
					case 1:
					{
						num1++;
						break;
					}
					case 2:
					{
						num2++;
						break;
					}
					case 3:
					{
						num3++;
						break;
					}
					case 4:
					{
						num4++;
						break;
					}
					case 5:
					{
						num5++;
						break;
					}
					case 6:
					{
						num6++;
						break;
					}
					case 7:
					{
						num7++;
						break;
					}
					case 8:
					{
						num8++;
						break;
					}
					case 9:
					{
						num9++;
						break;
					}
					case 10:
					{
						num10++;
						break;
					}
					default:
					{
						break;
					}
				}
			}
			
			trace("num10="+num10)
			trace("num9="+num9)
			trace("num8="+num8)
			trace("num7="+num7)
			trace("num6="+num6)
			trace("num5="+num5)
			trace("num4="+num4)
			trace("num3="+num3)
			trace("num2="+num2)
			trace("num1="+num1)
		}
	}
}